<html>
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  </head>
  <body>

<?php

    $username = $_POST["username"];
    $userpass = $_POST["userpass"];
           
    echo $username;   
    echo $userpass;  

//连接数据库
  $conn = mysql_connect("localhost","root","root");
 
  //选择数据库
  mysql_select_db("db_news", $conn);
 
  mysql_query("SET NAMES utf8");
 
 //获取界面传送的用户名和密码
  // $username = $_POST['username'];
  // $password = $_POST['password'];
  
  //执行SQL语句
  $sql = "select * from tbl_user where uname='$username'";
  echo $sql;
  $check_quary = mysql_query($sql);
 
  //将查询到的结果写入$result
  $result = array();
  $result = mysql_fetch_assoc($check_quary);
 
  //判断从前端获取的密码是否和数据库中的一样
  //一样，则跳转到目标网页
  if($userpass == $result['upass']){
    header("Location:http:../index.html");
  }
  else{
    //不一样则弹出提示框，回退到登录界面
    echo "<script>alert('用户名或密码不正确,请重新输入');history.back();</script>";
  }
?>
    
  </body>

</html>